package com.mingle.iwalk;

import java.util.ArrayList;  
import java.util.List;

import com.baidu.mapapi.ItemizedOverlay;
import com.baidu.mapapi.OverlayItem;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
//import com.google.android.maps.ItemizedOverlay;
//import com.google.android.maps.OverlayItem;

public class POIItemizedOverlay extends ItemizedOverlay<OverlayItem> {   
       
	public static final int POIITEM_ACTION_SHOW_BRIEF_INFO = 0;
	public static final int POIITEM_ACTION_SHOW_DETAIL_INFO = 1;
	
    private List<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>(); 
    private List<Integer> mPOIIds = new ArrayList<Integer>();
    private List<Integer> mActions = new ArrayList<Integer>();
    private Context mContext;

    public POIItemizedOverlay(Drawable defaultMarker,Context context) {  
        super(boundCenterBottom(defaultMarker));   
        mContext = context;

    }

	@Override
	protected OverlayItem createItem(int i) {
		
		 return mOverlayItems.get(i);
	}

	@Override
	public int size() {

		return mOverlayItems.size();
	}   
  
	@Override  
	protected boolean onTap(int index) {  
	    
		OverlayItem item = mOverlayItems.get(index);
		int action = mActions.get(index);
		switch(action)
		{
		case POIITEM_ACTION_SHOW_BRIEF_INFO:
		{
			String title = item.getTitle();
			String mesg = item.getSnippet();
			AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
			builder.setTitle(title).setMessage(mesg)
			.create().show();
		}
		break;
			
		case POIITEM_ACTION_SHOW_DETAIL_INFO:
		{
			Intent i = new Intent(mContext, POIActivity.class);
			i.putExtra("INFO_ID", mPOIIds.get(index));
			mContext.startActivity(i);
		}
		break;
		}
		
		return true;  
	}  
	 
	public void addOverlay(OverlayItem overlay, int Id, int action) {
		mOverlayItems.add(overlay);
		mPOIIds.add(Id);
		mActions.add(action);
	    populate();
	}
}  
